package cz.zcu.fav.rat.managed.bean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

import cz.zcu.fav.rat.beans.Indexable;

public class ObjectDataModel<T extends Indexable> extends ListDataModel<T> implements
		SelectableDataModel<T>
{

	private Map<Integer,T> map = new HashMap<Integer, T>(); 
	
	public ObjectDataModel(List<T> data)
	{
		super(data);
		for (T i : data) map.put(new Integer(i.getId()),i);
	}

	@Override
	public java.lang.Object getRowKey(T object)
	{
		return new Integer(object.getId());
	}
	
	@Override
	public T getRowData(String rowKey)
	{		
		return map.get(Integer.parseInt(rowKey));
	}

}
